﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;

namespace DAO
{
    public class ThamSo_DAO
    {
        public static ThamSo_DTO CreateThamSoDTO(ThamSo thamso)
        {
            ThamSo_DTO ThamSoDTO = new ThamSo_DTO();
            Mapper.CreateMap<ThamSo, ThamSo_DTO>();
            ThamSoDTO = Mapper.Map<ThamSo, ThamSo_DTO>(thamso);
            return ThamSoDTO;
        }

        public static ThamSo CreateThamSoEFF(ThamSo_DTO ThamSoDTO)
        {
            ThamSo thamso = new ThamSo();
            Mapper.CreateMap<ThamSo_DTO, ThamSo>();
            thamso = Mapper.Map<ThamSo_DTO, ThamSo>(ThamSoDTO);
            return thamso;
        }

        public ThamSo_DTO GetThamSoDetails()
        {
            ThamSo_DTO thamso = new ThamSo_DTO();
            try
            {
                QLCBDataContext context = new QLCBDataContext();
                var query = from cb in context.ThamSos
                                 select cb;
                ThamSo thamsoEF = query.First();
                thamso = CreateThamSoDTO(thamsoEF);
            }
            catch (System.Exception)
            { }
            return thamso;
        }
    }
}
